package com.example.administrator.hellocomp;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (ActivityCompat.checkSelfPermission( MainActivity.this,
                Manifest.permission.PROCESS_OUTGOING_CALLS)
                != PackageManager.PERMISSION_GRANTED ) {
            ActivityCompat.requestPermissions( MainActivity.this,
                    new String[] { Manifest.permission.PROCESS_OUTGOING_CALLS }, 123);
            return;
        }
        if (ActivityCompat.checkSelfPermission( MainActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED ) {
            ActivityCompat.requestPermissions( MainActivity.this,
                    new String[] {
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
                    }, 123);
            return;
        }
        if (ActivityCompat.checkSelfPermission( MainActivity.this,
                Manifest.permission.RECORD_AUDIO)
                != PackageManager.PERMISSION_GRANTED ) {
            ActivityCompat.requestPermissions( MainActivity.this,
                    new String[] { Manifest.permission.RECORD_AUDIO }, 123);
            return;
        }
//        Intent intent2 = new Intent(MainActivity.this,recorderService.class);
//        startService(intent2);
//        final String BROADCAST = "wust.zz.send";
////        if (ActivityCompat.checkSelfPermission( MainActivity.this,
////                Manifest.permission.PROCESS_OUTGOING_CALLS)
////                != PackageManager.PERMISSION_GRANTED ) {
////            ActivityCompat.requestPermissions( MainActivity.this,
////                    new String[] { Manifest.permission.PROCESS_OUTGOING_CALLS }, 123);
////            return;
////        }
////
////        final EditText et = (EditText)findViewById(R.id.edit_bc);
        Button bt = (Button)findViewById(R.id.bt_bc);
        bt.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent= new Intent(getApplicationContext(),recorderService.class);
                        Bundle bundle = new Bundle();
                        int msg = 1;
                        bundle.putInt("op",msg);
                        intent.putExtras(bundle);
                        startService(intent);
                        Log.d("msg","广播发送成功");
                    }
                }
        );

        Button btn_show = (Button)findViewById(R.id.btn_show);
        btn_show.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(),"点击了哦",Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(getApplicationContext(),listActivity.class);
//                        startActivity(intent);
                        startActivityForResult(intent, 200);
                    }
                }
        );


//        RadioGroup rg = (RadioGroup)findViewById(R.id.rg);
//        rg.setOnCheckedChangeListener(
//                new RadioGroup.OnCheckedChangeListener() {
//                    @Override
//                    public void onCheckedChanged(RadioGroup group, int checkedId) {
//                        EditText num_a = (EditText)findViewById(R.id.num_a);
//                        EditText num_b = (EditText)findViewById(R.id.num_b);
//                        RadioButton rb = (RadioButton)findViewById(checkedId);
//                        String a = num_a.getText().toString();
//                        String b = num_b.getText().toString();
//                        String op = rb.getText().toString();
//                        Intent intent=new Intent("wust.zz.mybroadcast");
//                        Bundle bundle=new Bundle();
//                        bundle.putString("a",a); bundle.putString("b",b); bundle.putString("op",op);
//                        intent.putExtras(bundle);
//                        sendBroadcast(intent);
//                        Log.d("msg","广播发送成功");
//
//
//                    }
//                }
//        );
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode==200)
            if(resultCode==RESULT_OK){
                onCreate(null);
            }
    }}
